<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>OnClick</title>
</head>
<body>
<h1 align="center">手电筒的打开与关闭</h1>

<p align="center">
    <img src="off.jpg" align="center" id="off">
</p>

<h1 align="center">
    <input id="open" type="button" onclick="changeImage(1)" value="打开" >    //设置打开按钮
    <input id="close" type="button" onclick="changeImage(0)" value="关闭">     //设置关闭按钮
</h1>

</body>
<script type="text/javascript">

    //定义一个带参的方法
    function changeImage(num) {
        var click = document.getElementById("off");  //转换dom对象元素
        if(num == 0){
            click.src="off.jpg";    //调用图片
            alert("手电筒已关闭");
        }
        else{
            click.src="on.jpg";   //调用图片
            alert("手电筒已打开");
        }
    }


</script>
</html>